2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #include "../../wrapper/juce_BrowserPluginComponent.h"
29 //==============================================================================
31 This is our top-level component for our plugin..
33 class JuceDemoBrowserPlugin
: public BrowserPluginComponent
,
34 public Button::Listener
37 JuceDemoBrowserPlugin()
39 addAndMakeVisible (textBox
= new TextEditor (String::empty
));
40 textBox
->setMultiLine (true);
41 textBox
->setBounds (8, 8, 300, 300);
43 addAndMakeVisible (button
= new TextButton ("Send a message to the webpage"));
44 button
->setBounds (320, 8, 180, 22);
45 button
->addListener (this);
46 button
->setEnabled (false);
48 ourJavascriptObject
= new DemoBrowserObject (this);
50 textBox
->setText ("Browser version info: " + getBrowserVersion());
53 ~JuceDemoBrowserPlugin()
58 const var
getJavascriptObject()
60 // The browser calls this to get the javascript object that represents our plugin..
61 return ourJavascriptObject
;
64 void paint (Graphics
& g
)
66 g
.fillAll (Colours::lightblue
);
69 void setJavascriptObjectFromBrowser (var callbackObject
)
71 javascriptObjectFromBrowser
= callbackObject
;
73 button
->setEnabled (javascriptObjectFromBrowser
.isObject());
76 void buttonClicked (Button
*)
78 javascriptObjectFromBrowser
.call ("printmessage", "This is a message sent from the plugin...");
81 var ourJavascriptObject
;
82 var javascriptObjectFromBrowser
;
86 //==============================================================================
87 /** This is the javascript object that the browser uses when the webpage accesses
88 methods or properties on our plugin object.
90 class DemoBrowserObject
: public DynamicObject
93 DemoBrowserObject (JuceDemoBrowserPlugin
* owner_
)
96 // Add a couple of methods to our object..
97 setMethod ("printText", (var::MethodFunction
) &DemoBrowserObject::printText
);
98 setMethod ("popUpMessageBox", (var::MethodFunction
) &DemoBrowserObject::popUpMessageBox
);
99 setMethod ("registerCallbackObject", (var::MethodFunction
) &DemoBrowserObject::registerCallbackObject
);
101 // Add some value properties that the webpage can access
102 setProperty ("property1", "testing testing...");
103 setProperty ("property2", 12345678.0);
110 //==============================================================================
111 // These methods are called by javascript in the webpage...
112 const var
printText (const var
* params
, int numParams
)
115 owner
->textBox
->setText (owner
->textBox
->getText() + "\n" + params
[0].toString());
117 return "text was printed ok!";
120 const var
popUpMessageBox (const var
* params
, int numParams
)
123 AlertWindow::showMessageBox (AlertWindow::InfoIcon
,
124 "A message from the webpage",
125 params
[0].toString(),
126 String::empty
, owner
);
130 const var
registerCallbackObject (const var
* params
, int numParams
)
133 owner
->setJavascriptObjectFromBrowser (params
[0]);
138 //==============================================================================
139 JuceDemoBrowserPlugin
* owner
;
143 BrowserPluginComponent
* JUCE_CALLTYPE
createBrowserPlugin()
145 return new JuceDemoBrowserPlugin();